how to find the sum of an array in java

79

sum of all numbers in array java -

int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);

how to find the sum of an array in java -

int [] arr = {1,2,3,4};
int sum = Arrays.stream(arr).sum(); //prints 10

Comments

Submit
0 Comments